package scau.mis4.chanyulin.atm.view;

import javafx.geometry.Insets;
import javafx.geometry.Pos;
import javafx.scene.Cursor;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.control.Label;
import javafx.scene.layout.*;
import javafx.stage.Modality;
import javafx.stage.Stage;

/**
 * Created by chanyulin on 2017/4/7
 * 警告、错误提示
 */
public class AlertStage extends Stage {

    public AlertStage(String title, String msg, double widthSize, double heightSize) {

        // 提示文本
        Label label = new Label(msg);
        label.setWrapText(true);
        label.setFocusTraversable(false);

        HBox msgBox = new HBox(10);
        msgBox.setAlignment(Pos.CENTER);
        msgBox.setPrefWidth(350);
        msgBox.getChildren().addAll(label);

        // 确定按钮
        Button ok = new Button("确定");
        ok.setPrefSize(64, 24);
        ok.setCursor(Cursor.HAND);
        ok.setFocusTraversable(false);
        ok.setOnAction(e -> {
            this.close();
        });

        HBox btBox = new HBox(12.5);
        btBox.setAlignment(Pos.CENTER);
        btBox.getChildren().addAll(ok);

        VBox vBox = new VBox(7.5);
        vBox.setAlignment(Pos.CENTER);
        vBox.setPadding(new Insets(2.5, 0, 0, 0));
        vBox.getChildren().addAll(msgBox, btBox);

        HBox hBox = new HBox();
        hBox.setAlignment(Pos.CENTER);
        hBox.setPrefSize(200 * widthSize, 120 * heightSize);
        hBox.getChildren().add(vBox);

        this.setTitle(title);
        this.setResizable(false);
        this.initModality(Modality.APPLICATION_MODAL);
        this.setScene(new Scene(hBox));

    }

    public AlertStage(String title, String msg) {
        this(title, msg, 1.0, 1.0);
    }

    public AlertStage(String msg) {
        this("提示", msg, 1.0, 1.0);
    }

}

